<?php

class LoginAction extends fvAction {
    
    function __construct () {
        parent::__construct(fvSite::$Layoult);
    }
    
    function executeIndex() {
        if (!fvRequest::getInstance()->isXmlHttpRequest()) {
            return self::$FV_OK;
        } else {
            return self::$FV_AJAX_CALL;
        }
    }
    
    function executeDeny() {
        if (!fvRequest::getInstance()->isXmlHttpRequest()) {
            return self::$FV_OK;
        } else {
            return self::$FV_AJAX_CALL;
        }    
    }
    
    function executeLogin() {
        $ManagerManager  = ManagerManager::getInstance();
        $request = fvRequest::getInstance();
        
        $LoggedManager = $ManagerManager->Login($request->getRequestParameter("login"), $request->getRequestParameter('password'));
        if ($LoggedManager instanceof Manager) {
            fvSite::$fvSession->setUser($LoggedManager);
            if (fvSite::$fvSession->is_set("login/redirectURL"))
                $this->redirect("@#" . fvSite::$fvConfig->get('dir_web_root') . fvSite::$fvSession->get("login/redirectURL"));
            else $this->redirect("@");
        } else {
            $this->redirect(fvSite::$fvConfig->get('access.login_page'));
        }
    }

    function executeLogout() {
        fvSite::$fvSession->setUser(false);
        $this->redirect("");
    }
}

?>
